/**
 * 暂时屏蔽 为了编译整个工程
 */
package labox.innovation.gameserver.communitybbs.Manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javolution.util.FastList;
import labox.innovation.db.core.L2DatabaseFactory;
import labox.innovation.gameserver.communitybbs.BB.Forum;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;

public class ForumsBBSManager extends BaseBBSManager {
	private static Logger _log = LoggerFactory.getLogger(ForumsBBSManager.class.getName());

	private List<Forum> _table;

	private int _lastid = 1;

	/**
	 * @return
	 */
	public static ForumsBBSManager getInstance() {
		return SingletonHolder._instance;
	}

	private ForumsBBSManager() {
		_table = new FastList<Forum>();

		Connection con = null;
		try {
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT forum_id FROM forums WHERE forum_type=0");
			ResultSet result = statement.executeQuery();
			while (result.next()) {
				int forumId = result.getInt("forum_id");
//				Forum f = new Forum(forumId, null);
//				addForum(f);
			}
			result.close();
			statement.close();
		} catch (Exception e) {
			_log.error("data error on Forum (root): ", e);
		} finally {
			try {
				con.close();
			} catch (Exception e) {
			}
		}
	}

	public void initRoot() {
//		for (Forum f : _table)
//			f.vload();
		_log.info("Loaded " + _table.size() + " forums. Last forum id used: " + _lastid);
	}

	public void addForum(Forum ff) {
		if (ff == null)
			return;

		_table.add(ff);

//		if (ff.getID() > _lastid) {
//			_lastid = ff.getID();
//		}
	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.communitybbs.Manager.BaseBBSManager#parsecmd(java.lang.String, labox.innovation.gameserver.model.actor.instance.L2PcInstance)
	 */
	@Override
	public void parsecmd(String command, FuzePcInstance activeChar) {
		// TODO Auto-generated method stub

	}

	/**
	 * @param string
	 * @return
	 */
	public Forum getForumByName(String Name) {
//		for (Forum f : _table) {
//			if (f.getName().equals(Name)) {
//				return f;
//			}
//		}

		return null;
	}

	/**
	 * @param name
	 * @param forumByName
	 * @return
	 */
	public Forum createNewForum(String name, Forum parent, int type, int perm, long oid) {
//		Forum forum = new Forum(name, parent, type, perm, oid);
//		forum.insertIntoDb();
		//addForum(forum); // not needed to addForum(Forum) because already called in new Forum(String, Forum, int, int, int)
		return null;
	}

	/**
	 * @return
	 */
	public int getANewID() {
		return ++_lastid;
	}

	/**
	 * @param idf
	 * @return
	 */
	public Forum getForumByID(int idf) {
//		for (Forum f : _table) {
//			if (f.getID() == idf) {
//				return f;
//			}
//		}
		return null;
	}

	/* (non-Javadoc)
	 * @see labox.innovation.gameserver.communitybbs.Manager.BaseBBSManager#parsewrite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, labox.innovation.gameserver.model.actor.instance.L2PcInstance)
	 */
	@Override
	public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, FuzePcInstance activeChar) {
		// TODO Auto-generated method stub

	}

	@SuppressWarnings("synthetic-access")
	private static class SingletonHolder {
		protected static final ForumsBBSManager _instance = new ForumsBBSManager();
	}
}